<!--
* @name: 自定义级联选择器
* @author: zhangpengcheng
* @date: 2022-08-19
-->
<template>
	<el-cascader v-model="model" ref="elCascader" :disabled="disabled" :clearable="clearable" :show-all-levels="showAllLevels"
	 :options="options" @change="change"></el-cascader>
</template>

<script>
	// import { areaGroupby } from "@/api/apis/auth.js";
	export default {
		name: "customCascader",
		components: {},
		props: {
			// 字段
			field: {
				type: String,
				default: ''
			},
			// 类型  1 组织或网格  2  场所类型
			type: {
				type: Number,
				default: 1
			},
			// 输入框中是否显示选中值的完整路径
			showAllLevels: {
				type: Boolean,
				default: false
			},
			// 是否支持清空选项
			clearable: {
				type: Boolean,
				default: true
			},
			// 是否禁用
			disabled: {
				type: Boolean,
				default: false
			},
			// 清除状态
			clearState: {
				type: Number,
				default: 0
			},
			// 清除状态
			modelData: {
				type: Array,
				default: () => {
					return []
				}
			},


		},
		data() {
			return {
				model: [],
				options: [],
			}
		},
		created() {},
		mounted() {
			this.areaGroupby()
		},
		watch: {
			// 监听数字变动，就重置
			clearState() {
				this.model = []
			}
		},
		computed: {

		},
		methods: {
			// 回显数据
			setEchoData(model) {
				this.model = model;
			},
			// 级联选择器更改值
			change() {
				let value = null;
				if (this.model.length != 0) {
					value = this.model[this.model.length - 1]
				}
				this.$emit('onChange', value, this.field)

			},
			// 查询函数
			areaGroupby() {
				// areaGroupby().then(res=>{
				//     let {code ,data} = res;
				//     if(code === 10000){
				//         let newData = [data]
				//         this.options = newData
				//     }
				// })
			},
		},
	}
</script>
<style scoped lang='scss'>

</style>
